package com.feige.controller;


import com.feige.service.UploadService;
import com.feige.result.AjaxResult;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;


/**
 * @author feige
 */
@Api(tags = "上传前端控制器")
@RestController
@RequestMapping("/courseware")
public class UploadController {

    @Resource
    private UploadService uploadService;

    /**
     * @description: 上传文件图片，语音，文件等
     * @author: feige
     * @date: 2021/3/1 15:48
     * @param	file
     * @return: com.feige.utils.result.AjaxResult
     */
    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file) throws IOException {
        return uploadService.upload(file);
    }

    /**
     * @description: 上传base64Data格式的图片
     * @author: feige
     * @date: 2021/3/1 15:49
     * @param	base64Data base64图片码
     * @return: com.feige.utils.result.AjaxResult
     */
    @PostMapping("/base64Upload")
    public AjaxResult uploadImage(@RequestBody String base64Data){
        return uploadService.uploadBase64Data(base64Data);
    }
}
